package cn.tx.date;

import cn.tx.util.DBUtil;

import java.sql.*;

public class Demo {
    public static void insertDate() throws SQLException {

        String sql="insert into dt (d,t,ts) values(?,?,?)";
        PreparedStatement statement = DBUtil.getPrepareStatement(sql);
        statement.setDate(1,new java.sql.Date(System.currentTimeMillis()));
        statement.setTime(2,new Time(System.currentTimeMillis()));
        statement.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
        statement.executeUpdate();
        DBUtil.closeRes(statement);



    }
    public static void getDate() throws SQLException {

        String sql="select * from dt";
        PreparedStatement statement = DBUtil.getPrepareStatement(sql);
        ResultSet rs = statement.executeQuery();
        if(rs.next()){
            Date date = rs.getDate(1);
            Time time = rs.getTime(2);

            Timestamp timestamp = rs.getTimestamp(3);
            System.out.println(date);
            System.out.println(time);
            System.out.println(timestamp);

        }
        DBUtil.closeRes(rs);



    }

    public static void main(String[] args) throws SQLException {
        getDate();
    }
}
